<#include "/common/_layout.html"/>
<@layout>
<script>
	$(function() {
		$('#dg').datagrid({
			url:'/stocksignal/paginate',
			rownumbers:true,
			pagination:true,
			pageList:[50,100,200],
			pageSize:50,
			fitColumns:true,
			multiple:true,
			fixRowHeight:null,
			columns:[[
				{field:'id',title:'id',checkbox:true},
				{field:'stockCode',title:'股票代码'},
				{field:'stockUrl',title:'路径', 
					formatter: function(value, row, index) {
						return '<a target="_blank" href="http://quote.eastmoney.com/' + row.stockCode + '.html">http://quote.eastmoney.com/' + row.stockCode + '.html</a>';
				}},
				{field:'isLeftEye',title:'左耳'},
				{field:'isRightEye',title:'右耳'},
				{field:'symbol',title:'日K线', width:400,
					formatter: function(value, row, index) {
						return '<img src="http://image.sinajs.cn/newchart/daily/n/' + value + '.gif"/>';
					}}
			]]
		});
		
		//初始化添加页面
		$('#rec_form').form({
			method:'post',
			url:'/recommend/save',
			success:function(data) {
				var obj = eval('(' + data + ')');
				if(obj.success) {
					$('#form_win').window('close');
					$.messager.alert('提示', obj.msg);
				}
			}
		});
	});
		
	// 查询方法
	function getData() {
		var stockCode = $('#stock_code').textbox('getValue');
		var signalType = $('#signal_type').combobox('getValue');
		var searchUrl = "/stocksignal/paginate?stockCode=" + stockCode + "&signalType=" + signalType;
		$('#dg').datagrid({
			url:searchUrl,
			pageNumber:1,
			fixRowHeight:null
		});
	}
	
	//添加关注
	function addOptional() {
		//获取选中的行
		var row = $('#dg').datagrid('getSelected');
		if(row == null) {
			$.messager.alert('错误','请选择数据后再进行操作!');
			return;
		}
		
		var obj = {
		  'optional.symbol':row.symbol,
		  'optional.stockCode':row.stockCode
		};
		page_post_ajax('/optional/save', obj, 'saveCallback', '');
	}
	
	//添加推荐
	function addRecommend() {
		//获取选中的行
		var row = $('#dg').datagrid('getSelected');
		if(row == null) {
			$.messager.alert('错误','请选择数据后再进行操作!');
			return;
		}
		$('#symbol').textbox('setValue', row.symbol);
		$('#stockCode').val(row.stockCode);
		$('#form_win').window('open');
		 
	}
	
	//添加回调函数
	function saveCallback(msg) {
		if(1 == msg.errCode) {
			openLoginWindow();
			return;
		}
		if(2 == msg.errCode) {
			$.messager.alert('错误', msg.errMsg);
			return;
		}
		if(0 == msg.errCode) {
			$.messager.alert('提示','添加成功!');
			return;
		}
	}
	
	function submitForm(){
		$('#rec_form').form('submit');
	}
	function clearForm(){
		$('#rec_form').form('clear');
	}
	
	// 删除方法
	function remove() {
		var stockCodesStr = "";
		var rows = $('#dg').datagrid('getSelections');
		for(var i = 0; i < rows.length; i++) {
			stockCodesStr += rows[i].stockCode + ',';
		}
		
		stockCodesStr = stockCodesStr.substring(0, stockCodesStr.length - 1);
		
		$.ajax({
			type : 'POST',
			url  : '/stocksignal/delete',
			data : {
				'stockCodesStr':stockCodesStr
			},
			success : function(result) {
				if(result && result.success) {
					getData();
				}
			}
		});
	}
</script>

<div class="table_box" style="padding-bottom: 5px">
	<!-- 导入工具栏 -->
	<#include "/common/_toolbar.html"/>
	<@toolbar toolbarArr = [['btn_add','icon-add','addOptional()','添加关注']
	                       ,['btn_edit','icon-edit','addRecommend()','添加推荐']
	                       ,['btn_remove','icon-remove','remove()','删除']]
	          optionArr = [{'id':'stock_code', 'label':'股票代码', 'type':'input', 'prompt':'请输入股票代码'}
	          			  ,{'id':'signal_type', 'label':'类别', 'type':'select', 'optionArr':[{'name':'未选择','value':''},{'name':'买入信号','value':'1'},{'name':'卖出信号','value':'2'}]}]/>
</div>

<table id="dg" style="height:698px"></table>

<!-- 添加页面 -->
<div id="form_win" class="easyui-window" title="添加定时任务" style="width:600px;height:400px"
        data-options="iconCls:'icon-save',modal:true,closed:true">
	<div style="padding:10px 60px 20px 60px">
	<form id="rec_form">
		<table cellpadding="5">
			<tr>
				<td>股票编码:</td>
				<td><input class="easyui-textbox" type="text" name="recommend.symbol" id="symbol" data-options="readonly:true"></td>
			</tr>
			<tr>
				<td>推荐买入价格:</td>
				<td><input class="easyui-textbox" type="text" name="recommend.buyPrice" data-options="required:true, missingMessage:'请输入入场价格'"></td>
			</tr>
		</table>
		<input type="hidden" name="recommend.stockCode" id="stockCode">
	</form>
	<div style="text-align:center;padding:5px">
		<a href="#" class="easyui-linkbutton" onclick="submitForm()">提交</a>
	</div>
	</div>
</div>
</@layout>